package com.dashanchessgame.chess;

import com.dashanchessgame.tools.ImageTool;
import com.dashanchessgame.tools.WinUtils;

import java.awt.*;

/**
 * 马
 *
 * @author 37460
 */
public class ChessHorse implements Chess {
    @Override
    public boolean chessCheck(int[][] map, int nowLineNumber, int nowColumnNumber, int toLineNumber, int toColumnNumber, boolean isChessColor) {
        //获取相差的行数和列数
        int istoLineNumber = Math.abs(nowLineNumber - toLineNumber);
        int istoColumnNumber = Math.abs(nowColumnNumber - toColumnNumber);
        int listLineNumber = 0;
        int columnNumber = 0;
        //判断马是不是走的日
        if ((istoLineNumber == 2 && istoColumnNumber == 1) || (istoLineNumber == 1 && istoColumnNumber == 2)) {
            //判断横着走正上方的的棋子
            if (istoColumnNumber == 1) {
                listLineNumber = (nowLineNumber + toLineNumber) / 2;
                columnNumber = nowColumnNumber;
            } else {
//              判断竖着走正上方的棋子
                listLineNumber = nowLineNumber;
                columnNumber = (nowColumnNumber + toColumnNumber) / 2;
            }
//             判断行进方向正上方有没有棋子
            if (map[listLineNumber][columnNumber] == 0) {
//                判断对方是不是将
                return WinUtils.win(map, toLineNumber, toColumnNumber, isChessColor);
            }
        }
        return false;
    }

    @Override
    public int getType() {
        return 'M';
    }


    @Override
    public Image getImage(boolean isChessColor) {

        return ImageTool.loadImage(isChessColor ? "黑马.gif" : "红马.gif");
    }
}
